Repository navigation
feat(sync): Binance USDⓈ-M futures history - #57
Merged
Merged
Conversation
broker-sdk 0.6.0 returns Binance USDⓈ-M futures fills (three months of history) and marks hedge-mode fills and positions with their side. - A hedge-mode fill is journaled in its side's group (sync-hedge:long or sync-hedge:short). A long and a short held at once on one symbol then stay two trades instead of netting. Sync rows may now carry import metadata for this. - Binance's futures position list vouches for unlabeled futures fills, as Webull's does for equities. A close of a position opened before the three months is skipped, or kept for the part the history covers. Hedge-mode positions stay out of that check, since their sides replay in their own groups. - A Binance quarterly contract settles at delivery without a fill, so its flat position can't show its history is incomplete. Its fills are kept, and one held to delivery stays open.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #56, which should merge first; this PR's base then moves to
main.Syncs Binance USDⓈ-M futures into the journal, using broker-sdk 0.6.0 (#30).
Cause
broker-sdk's Binance adapter returned no fills, so a Binance account's dashboard, calendar and reports stayed empty. broker-sdk 0.6.0 reads USDⓈ-M futures fills (LuxAlgo/broker-sdk#25), as #30 asked for. Once those fills arrive, the journal side has two problems:
Fix
Trade.positionSideis journaled in a group for its side,sync-hedge:longorsync-hedge:short. The round-trip engine keeps groups apart, as it does for separately reported positions in imports. Sync rows may now carry import metadata to hold the group. One-way fills are unchanged.keepWithinHistoryfrom fix(sync): Webull trade history without phantom positions #56, which replays each group on its own and keeps only the part of a close that the history covers.BTCUSDT_261225) settles at delivery without a fill, so the position list can't say whether its history is complete. Its fills are kept, and one held to delivery stays open. The docs say so.Test
apps/web/tests/binance-sync.test.tsrunssyncAccountwith broker-sdk's Binance adapter against a stubbed Binance:The hedge, history-limit and delivery tests each fail without their part of the fix.
Checks run locally
All of these pass:
pnpm format:checkpnpm typecheckpnpm test(71 files, 665 tests)node scripts/check-licenses.mjspnpm -r --filter "./packages/*" buildpnpm buildFixes #30